﻿
@page "/Wms/BuyReturnOutWarehouseDetail/Edit"
@using nERP.ViewModel.Wms.BuyReturnOutWarehouseDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
  <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit" >
    <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
      <BootstrapInput @bind-Value="@Model.Entity.Seq"/>
      <Select @bind-Value="@Model.Entity.BuyReturnId" Items="AllBuyReturns" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="gbb351384480543348abaf3c7a17a6c9a"/>
      <Select @bind-Value="@Model.Entity.BuyReturnOutWarehouseId" Items="AllBuyReturnOutWarehouses" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="ge5cac33f87d645be92e5d6cb3e4bed7a"/>
      <Select @bind-Value="@Model.Entity.BuyId" Items="AllBuys" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g17ccb9dd93e042f7aae043759241aaaf"/>
      <BootstrapInput @bind-Value="@Model.Entity.BuyReturnOutWarehouseDetailCode"/>
      <Select @bind-Value="@Model.Entity.BuyDetailId" Items="AllBuyDetails" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g412e2944442e4dfbab4c78ede0197f6f"/>
      <Select @bind-Value="@Model.Entity.WarehouseId" Items="AllWarehouses" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="g974be34f8a34460a922611703e447162"/>
      <Select @bind-Value="@Model.Entity.GoodsId" Items="AllGoodss" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" Id="ga1d74561e9434159bb9a5605ebb37c53"/>
      <BootstrapInput @bind-Value="@Model.Entity.GoodsName"/>
      <BootstrapInput @bind-Value="@Model.Entity.GoodsSpec"/>
      <BootstrapInput @bind-Value="@Model.Entity.GoodsUnit"/>
      <BootstrapInput @bind-Value="@Model.Entity.ReturnNumber"/>
      <BootstrapInput @bind-Value="@Model.Entity.Remark"/>
    </Row>

    <div class="modal-footer table-modal-footer">
      <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]"/>
      <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]"/>
    </div>

  </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private BuyReturnOutWarehouseDetailVM Model = new BuyReturnOutWarehouseDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {
                        
        
        await PostsForm(vform, "/api/Wms/BuyReturnOutWarehouseDetail/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }
    
    private List<SelectedItem> AllBuyReturns = new List<SelectedItem>();
    private List<SelectedItem> AllBuyReturnOutWarehouses = new List<SelectedItem>();
    private List<SelectedItem> AllBuys = new List<SelectedItem>();
    private List<SelectedItem> AllBuyDetails = new List<SelectedItem>();
    private List<SelectedItem> AllWarehouses = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {
        
        
        AllBuyReturns = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetBuyReturns");
        AllBuyReturns.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllBuyReturnOutWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetBuyReturnOutWarehouses");
        AllBuyReturnOutWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllBuys = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetBuys");
        AllBuys.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllBuyDetails = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetBuyDetails");
        AllBuyDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetWarehouses");
        AllWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<BuyReturnOutWarehouseDetailVM>($"/api/Wms/BuyReturnOutWarehouseDetail/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
